/*     */ package com.zimbra.cs.httpclient;
/*     */ 
/*     */ import com.zimbra.common.localconfig.KnownKey;
/*     */ import com.zimbra.common.localconfig.LC;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Provisioning.MailMode;
/*     */ import com.zimbra.cs.account.Server;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class URLUtil
/*     */ {
/*     */   public static final String PROTO_HTTP = "http";
/*     */   public static final String PROTO_HTTPS = "https";
/*  46 */   public static int DEFAULT_HTTP_PORT = 80;
/*  47 */   public static int DEFAULT_HTTPS_PORT = 443;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public static String getSoapURL(Server server, boolean preferSSL)
/*     */     throws ServiceException
/*     */   {
/*  55 */     return getServiceURL(server, "/service/soap/", preferSSL);
/*     */   }
/*     */   
/*     */   public static String getSoapPublicURL(Server server, Domain domain, boolean preferSSL) throws ServiceException {
/*  59 */     return getPublicURLForDomain(server, domain, "/service/soap/", preferSSL);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static String getAdminURL(Server server, String path)
/*     */   {
/*  70 */     String hostname = server.getAttr("zimbraServiceHostname");
/*  71 */     int port = server.getIntAttr("zimbraAdminPort", 0);
/*  72 */     StringBuffer sb = new StringBuffer(128);
/*  73 */     sb.append(LC.zimbra_admin_service_scheme.value()).append(hostname).append(":").append(port).append(path);
/*  74 */     return sb.toString();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static String getAdminURL(Server server, String path, boolean checkPort)
/*     */     throws ServiceException
/*     */   {
/*  86 */     String hostname = server.getAttr("zimbraServiceHostname");
/*  87 */     int port = server.getIntAttr("zimbraAdminPort", 0);
/*  88 */     if ((checkPort) && (port <= 0))
/*  89 */       throw ServiceException.FAILURE("server " + server.getName() + " does not have admin port enabled", null);
/*  90 */     StringBuffer sb = new StringBuffer(128);
/*  91 */     sb.append(LC.zimbra_admin_service_scheme.value()).append(hostname).append(":").append(port).append(path);
/*  92 */     return sb.toString();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static String getAdminURL(String hostname)
/*     */   {
/* 103 */     int port = (int)LC.zimbra_admin_service_port.longValue();
/* 104 */     StringBuffer sb = new StringBuffer(128);
/* 105 */     sb.append(LC.zimbra_admin_service_scheme.value()).append(hostname).append(":").append(port).append("/service/admin/soap/");
/* 106 */     return sb.toString();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static String getAdminURL(Server server)
/*     */   {
/* 117 */     return getAdminURL(server, "/service/admin/soap/");
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static String getMtaAuthURL(String authHost)
/*     */     throws ServiceException
/*     */   {
/* 127 */     for (Server server : Provisioning.getInstance().getAllServers()) {
/* 128 */       String serviceName = server.getAttr("zimbraServiceHostname", null);
/* 129 */       if (authHost.equalsIgnoreCase(serviceName)) {
/* 130 */         return getSoapURL(server, true);
/*     */       }
/*     */     }
/* 133 */     throw ServiceException.INVALID_REQUEST("specified zimbraMtaAuthHost does not correspond to a valid service hostname: " + authHost, null);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static String getPublicURLForDomain(Server server, Domain domain, String path, boolean preferSSL)
/*     */     throws ServiceException
/*     */   {
/* 146 */     String publicURLForDomain = getPublicURLForDomain(domain, path);
/* 147 */     if (publicURLForDomain != null) {
/* 148 */       return publicURLForDomain;
/*     */     }
/*     */     
/* 151 */     return getServiceURL(server, path, preferSSL);
/*     */   }
/*     */   
/*     */   private static String getPublicURLForDomain(Domain domain, String path) {
/* 155 */     if (domain == null) {
/* 156 */       return null;
/*     */     }
/* 158 */     String hostname = domain.getAttr("zimbraPublicServiceHostname", null);
/* 159 */     if (hostname == null) {
/* 160 */       return null;
/*     */     }
/* 162 */     String proto = domain.getAttr("zimbraPublicServiceProtocol", "http");
/*     */     
/* 164 */     int defaultPort = "http".equals(proto) ? DEFAULT_HTTP_PORT : DEFAULT_HTTPS_PORT;
/* 165 */     int port = domain.getIntAttr("zimbraPublicServicePort", defaultPort);
/*     */     
/* 167 */     boolean printPort = (("http".equals(proto)) && (port != DEFAULT_HTTP_PORT)) || (("https".equals(proto)) && (port != DEFAULT_HTTPS_PORT));
/*     */     
/*     */ 
/* 170 */     StringBuilder buf = new StringBuilder();
/* 171 */     buf.append(proto).append("://").append(hostname);
/* 172 */     if (printPort)
/* 173 */       buf.append(":").append(port);
/* 174 */     buf.append(path);
/* 175 */     return buf.toString();
/*     */   }
/*     */   
/*     */   public static String getServiceURL(Server server, String path, boolean useSSL) throws ServiceException
/*     */   {
/* 180 */     String hostname = server.getAttr("zimbraServiceHostname");
/* 181 */     if (hostname == null) {
/* 182 */       throw ServiceException.INVALID_REQUEST("server " + server.getName() + " does not have " + "zimbraServiceHostname", null);
/*     */     }
/* 184 */     String modeString = server.getAttr("zimbraMailMode", null);
/* 185 */     if (modeString == null)
/* 186 */       throw ServiceException.INVALID_REQUEST("server " + server.getName() + " does not have " + "zimbraMailMode" + " set, maybe it is not a store server?", null);
/* 187 */     Provisioning.MailMode mailMode = Provisioning.MailMode.fromString(modeString);
/*     */     int port;
/*     */     String proto;
/*     */     int port;
/* 191 */     if (((mailMode != Provisioning.MailMode.http) && (useSSL)) || (mailMode == Provisioning.MailMode.https)) {
/* 192 */       String proto = "https";
/* 193 */       port = server.getIntAttr("zimbraMailSSLPort", DEFAULT_HTTPS_PORT);
/*     */     } else {
/* 195 */       proto = "http";
/* 196 */       port = server.getIntAttr("zimbraMailPort", DEFAULT_HTTP_PORT);
/*     */     }
/*     */     
/* 199 */     StringBuilder buf = new StringBuilder();
/* 200 */     buf.append(proto).append("://").append(hostname);
/* 201 */     buf.append(":").append(port);
/* 202 */     buf.append(path);
/* 203 */     return buf.toString();
/*     */   }
/*     */   
/*     */   public static boolean reverseProxiedMode(Server server) throws ServiceException {
/* 207 */     String referMode = server.getAttr("zimbraMailReferMode", "wronghost");
/* 208 */     return "reverse-proxied".equals(referMode);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/httpclient/URLUtil.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */